#!/bin/bash
#
#############################################
# --- WikiRando.sh ---                      #
#                                           #
# Get random subject from English Wikipedia #
#                                           #
#############################################


# Logic behind this is as follows:-
#
# 1. Grab a random page from wikipedia using wget, and keep output quiet - save as temp file
# 2. Pipe the resulting html into grep, only looking for the line that containers the page <title> - equivalent to subject
# 3. Strip the opening html tag using cut
# 4. Reverse the string from that line
# 5. Remove the closing title tag, and the " - Wikipedia" portion of thepage title
# 6. Reverse the string back to normal orientation, to keep it human-readable, and output to stdout
# 7. Remove temp file


wget -O temp.html -q https://en.wikipedia.org/wiki/Special:Random
cat temp.html | grep "<title>" | cut -c 8- | rev | cut -c 21- | rev
rm temp.html


# Although this is just a simple script and could be incorporated into any script, I can
# forsee a few use-cases where getting a random subject from Wikipedia to be useful.
# And, ya know, UNIX philosphy - do one thing and do it well

# This is part of my web-use "Chaffer" - props to Cory Doctorow's book homeland for the impetus

